home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / UCD.ASM < prev    next >
Assembly Source File  |  1989-12-07  |  5KB  |  182 lines

  1. ;  UCD.COM
  2. ;
  3. ;  Uwe H. Steinfeld, 12/07/89
  4. ;
  5. ;  Syntax:     UCD [drive:][directory]
  6. ;
  7. ;  Features:   - fully replaces and enhances DOS' CD
  8. ;           - is able to change drive and directory simultaneously
  9. ;           - does not need a complete path to the target directory,
  10. ;         searches recursively through the directory tree
  11. ;
  12. ;  Limitation: - if two directories with the      D:\
  13. ;         same name in the tree exist       │
  14. ;         only the first will be found.       ├─ STATS
  15. ;         You have to give the name of       │    ├─ EXCEL
  16. ;         the parent directory to go       │    │   └──── DATA
  17. ;         to the desired one, e.g.,       │    └─ STATG
  18. ;         to go to the second data       │        └──── DATA
  19. ;         directory on drive D: use
  20. ;             UCD D:STATG\DATA
  21. ;
  22. ;  Errorlevel:    0  success
  23. ;        1  directory not found
  24. ;        2  invalid drive
  25.  
  26.  
  27. include dos.inc              ; MASM macros for better readable code
  28.  
  29. directory    equ    10000b         ; directory attribute
  30.  
  31. text        segment
  32.         assume cs:text, ds:text, es:text
  33.  
  34.         org    100h
  35.  
  36. start:        jmp    ucd
  37.  
  38. Copyright:    db    '(C) Uwe H. Steinfeld, 12/07/89'
  39. SaveDrive    db    0, ':\'
  40. SaveDir     db    64 dup (0),'$'
  41. search        db    64 dup (0)
  42. root        db    '\', 0
  43. parent        db    '..', 0
  44. wild        db    '*.*', 0
  45. msg1        db    'Invalid directory', 0Dh, 0Ah, '$'
  46. msg2        db    'Invalid drive', 0Dh, 0Ah, '$'
  47.  
  48.  
  49. ucd:        @GetDrv              ; save current drive and path
  50.         mov    SaveDrive,al         ;   to go back if the search
  51.         @GetDir SaveDir          ;   is unsuccessful
  52.  
  53.         mov    si,81h             ; start of command tail
  54.         mov    di,offset search     ; ASCIIZ path storage
  55. Uc_1:        lodsb
  56.         cmp    al,' '                   ; skip leading blanks and
  57.         jz    Uc_1             ;   tabs in the command tail
  58.         cmp    al,9
  59.         jz    Uc_1
  60.         cmp    al,0Dh             ; end of command line ?
  61.         jnz    Uc_2
  62.  
  63.         add    cs:SaveDrive,'A'         ; no cmd line argument, just
  64.         @DispStr SaveDrive         ;    display current drive
  65.         @Exit 0              ;    and path and terminate
  66.  
  67. Uc_2:        mov    dl,al             ; save first letter
  68.         lodsb                 ; get next
  69.         cmp    al,':'                   ; drive specified ?
  70.         jnz    Uc_5
  71.  
  72. ;  set new drive
  73.  
  74.         and    dl,0DFh          ; adjust to uppercase
  75.         sub    dl,'A'                   ; drive A=0, B=1, ...
  76.         mov    ah,0Eh             ; set new drive
  77.         int    21h
  78.         @GetDrv              ; get drive
  79.         cmp    al,dl             ; successful changed ?
  80.         jz    Uc_3
  81.         @DispStr msg2             ; invalid drive specified
  82.         @Exit    2             ; exit with errorlevel 2
  83.  
  84. Uc_3:        lodsb                 ; get next character
  85.         call    ChkEnd             ; only new drive given ?
  86.         jnz    Uc_4
  87.         @Exit 0              ; done
  88.  
  89. Uc_4:        mov    dl,al             ; save first letter
  90.         lodsb
  91.  
  92. Uc_5:        xchg    dl,al             ; no drive given, so
  93.         stosb                 ;   store saved characters
  94.         xchg    al,dl
  95.         call    ChkEnd             ; only 1 char on cmd line ?
  96.         jnz    Uc_7
  97.  
  98. ;  target directory only 1 character long, check for '\' and '.'
  99.  
  100.         cmp    dl,'.'                   ; was it 'current' dir ?
  101.         jnz    Uc_6
  102.         @Exit    0             ; then we're done
  103.  
  104. Uc_6:        cmp    dl,'\'                   ; was it root dir ?
  105.         jnz    Uc_8
  106.         @ChDir    root             ; then go to root dir
  107.         @Exit    0             ;   and quit
  108.  
  109. ;  more than 1 directory letter so check for '..'
  110.  
  111. Uc_7:        cmp    al,'.'                   ; test first character
  112.         jnz    Uc_8
  113.         cmp    al,dl             ; compare to second
  114.         jnz    Uc_8
  115.         @ChDir    parent             ; change to parent directory
  116.         @Exit  0             ; and exit
  117.  
  118. ; read rest of command tail
  119.  
  120. Uc_8:        stosb
  121.         lodsb                 ; get the rest of the cmd tail
  122.         call    ChkEnd             ; don't care about what comes
  123.         jnz    Uc_8             ;   after the first word
  124.  
  125. ;  search begins
  126.  
  127.         mov    di,offset DTAInit     ; ptr to start of DTA area
  128.         @ChDir    root             ; start in the root directory
  129.         call    tree             ;   and call the subroutine
  130.         mov    dl,SaveDrive         ; if we return here then the
  131.         mov    ah,0Eh             ;   directory was not found,
  132.         int    21h             ;   so restore the starting
  133.         @ChDir SaveDir             ;   drive/dir and stop with
  134.         @DispStr msg1             ;   error message
  135.         @Exit 1
  136.  
  137. ;  tree search (recursively)
  138.  
  139. tree:        call    setDTA             ; set DTA for GetFirst/Next
  140.         @GetFirst search,directory     ; is 'target' subdirectory
  141.         jc    t1             ;   of the current dir ?
  142.         cmp    byte ptr[di+15h],directory
  143.         jnz    t1
  144.         @ChDir search             ; then change to it and
  145.         @Exit 0              ;   exit with success code
  146.  
  147. t1:        @GetFirst wild,directory     ; look for subdirectories...
  148. t2:        jc    t4
  149.         cmp    byte ptr[di+15h],directory
  150.         jnz    t3
  151.         cmp    byte ptr[di+1Eh],'.'     ; ... but not '.' or '..'
  152.         jz    t3
  153.         mov    dx,di             ; change directory to
  154.         add    dx,1Eh             ;   the one found
  155.         mov    ah,3Bh
  156.         int    21h
  157.         add    di,43             ; increase dta ptr
  158.         call    tree             ;    and start over
  159.         @ChDir    parent             ; come back if not found
  160.         sub    di,43             ; set dta ptr back
  161.         call    setDTA
  162. t3:        @GetNext             ; find next subdirectory
  163.         jmp    t2
  164. t4:        ret
  165.  
  166. setDTA:     mov    dx,di             ; set new disk transfer area
  167.         mov    ah,1Ah
  168.         int    21h
  169.         ret
  170.  
  171. ChkEnd:     cmp    al,' '                   ; get byte from command line
  172.         jz    ChkRet             ;   and check for end of
  173.         cmp    al,9             ;   line condition
  174.         jc    ChkRet
  175.         cmp    al,0Dh
  176. ChkRet:     ret
  177.  
  178. DTAInit:                     ; start of first DTA
  179.  
  180. text        ends
  181.         end    start
  182.